<template>
  <el-form label-width="80px" label-position="right">
    <el-row :gutter="8">
      <el-col :span="8">
        <el-form-item label="调用指令" required>
          <el-input v-model="seqInfo.callCmd" />
        </el-form-item>
      </el-col>
      <el-col :span="8">
        <el-form-item label="规则名称">
          <el-input v-model="seqInfo.seqName" />
        </el-form-item>
      </el-col>
      <el-col :span="8">
        <el-form-item label="流水号" required>
          <el-input-number v-model="seqInfo.seqNumber" :min="1" :max="5" style="width: 100%" controls-position="right" />
        </el-form-item>
      </el-col>
    </el-row>
    <el-form-item label="编号规则" required>
      <el-input type="textarea" :rows="2" v-model="seqInfo.seqFormat" />
    </el-form-item>
    <el-form-item label="关键字" required>
      <el-input v-model="seqInfo.keyWord" />
    </el-form-item>
    <el-form-item label-width="0" style="text-align: center">
      <el-button-group>
        <el-button type="success" icon="el-icon-check" @click="saveSeq">{{ seqInfo.ruleId ? '更新' : '保存' }}</el-button>
      </el-button-group>
      <seq-max-table v-if="seqInfo.ruleId" :rule-id="seqInfo.ruleId" />
    </el-form-item>
  </el-form>
</template>

<script>
import SeqMaxTable from "@/views/system/db/seq/SeqMaxTable";
export default {
  name: "SeqInfo",
  components: {SeqMaxTable},
  props: {
    seqInfo: {
      type: Object,
      default: function () {
        return {}
      }
    }
  },
  data() {
    return {
      loading: false
    }
  },
  methods: {
    saveSeq() {
      this.loading = true
      this.$post('ruleSeq/save', this.seqInfo)
          .then(res => {
            this.$resultMsg(this, res)
            if (res.code === 200) {
              this.$set(this.seqInfo, 'ruleId',res.data.ruleId)
              this.$emit('save', this.seqInfo)
            }
            setTimeout(() => {
              this.loading = false
            }, 200)
          })
    }
  }
}
</script>

<style scoped>

</style>
